package com.tinama.jedis01.queue;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author lgc
 * @createDate 2020/10/14 - 9:57
 */
public class SynchronousQueueTest {
    public static void main(String[] args){
        SynchronousQueue<String> sq = new SynchronousQueue<>();

        new Thread(()->{
            try {
                System.out.println(Thread.currentThread().getName()+" put /t"+"G");
                sq.put("G");

                System.out.println(Thread.currentThread().getName()+" put /t"+"A");
                sq.put("A");

                System.out.println(Thread.currentThread().getName()+" put /t"+"B");
                sq.put("B");

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t1").start();

        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(3);
                System.out.println(Thread.currentThread().getName()+" take /t"+ sq.take());

                TimeUnit.SECONDS.sleep(3);

                System.out.println(Thread.currentThread().getName()+" take /t"+ sq.take());
                TimeUnit.SECONDS.sleep(3);

                System.out.println(Thread.currentThread().getName()+" take /t"+ sq.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t2").start();
    }

}
